package com.yaozheng.vocationaltraining.service.impl;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.IMasterQuestionView;
import com.yaozheng.vocationaltraining.service.MasterQuestionService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * 闯关题目服务
 */
@EBean
public class MasterQuestionServiceImpl implements MasterQuestionService {
    IMasterQuestionView iMasterQuestionView;

    @Override
    public void init(IMasterQuestionView iMasterQuestionView) {
        this.iMasterQuestionView = iMasterQuestionView;
    }

    @Background
    @Override
    public void getQuestionList(int id, int step) {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/exam/master?id=" + id + "&step="
                            + step, iMasterQuestionView.getToken(),
                    new OkHttpClientManager.IBaseViewCallback(new BaseView(iMasterQuestionView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMasterQuestionView.getQuestionListSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMasterQuestionView.getQuestionListError(error);

                        }


                    }));
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMasterQuestionView.isResponseResult()) {
                iMasterQuestionView
                        .getQuestionListError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
